<style>
    form {
        margin: 0;
    }

    textarea {
        display: block;
    }
</style>
<script charset="utf-8" src="/plugin/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="/plugin/kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="/plugin/jquery/jquery-1.7.1.js"></script>
<script>
    var editor;
    KindEditor.ready(function (K) {
        editor = K.create('textarea[name="content"]', {
            uploadJson:'/index.php/upload/index',
            allowFileManager:true
        });
        K('input[name=getHtml]').click(function (e) {
            alert(editor.html());
        });
        K('input[name=isEmpty]').click(function (e) {
            alert(editor.isEmpty());
        });
        K('input[name=getText]').click(function (e) {
            alert(editor.text());
        });
        K('input[name=selectedHtml]').click(function (e) {
            alert(editor.selectedHtml());
        });
        K('input[name=setHtml]').click(function (e) {
            editor.html('<h3>Hello KindEditor</h3>');
        });
        K('input[name=setText]').click(function (e) {
            editor.text('<h3>Hello KindEditor</h3>');
        });
        K('input[name=insertHtml]').click(function (e) {
            editor.insertHtml('<strong>插入HTML</strong>');
        });
        K('input[name=appendHtml]').click(function (e) {
            editor.appendHtml('<strong>添加HTML</strong>');
        });
        K('input[name=clear]').click(function (e) {
            editor.html('');
        });
    });
</script>


<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
    <TBODY>
    <TR>
        <TD width=15></TD>
        <TD width="100%" height=20></TD>
        <TD width=15></TD>
    </TR>
    </TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
    <TBODY>
    <TR>
        <TD width=15></TD>
        <TD vAlign=top width="100%" bgColor=#ffffff>
            <form action="saveAdd" method="post">
                <?php if (isset($domain)) echo '<input type="hidden" name="id" value="' . $domain->id . '" />' ?>
                <TABLE borderColor=#cccccc cellSpacing=0 cellPadding=0 width="100%"
                       align=center border=0>
                    <TBODY>
                    <tr>
                        <td style="color: red"><?php if (isset($message)) echo $message ?></td>
                    </tr>
                    <TR>
                        <TD style="width: 10%">栏目分类</TD>
                        <TD style="width: 90%">
                            <b
                                id="articleTypeName"><?php if (isset($typeName)) echo $typeName;  ?></b>

                            <b id="articleTypeArea" <?php if (isset($typeName)) echo 'style="display:none"';  ?>>
                                <select id="parentType" name="type_id">
                                    <?php
                                    foreach ($parentType as $key => $value) {
                                        ?>
                                        <option <?php if (isset($domain) && $domain->type_id == $value->id) echo 'selected=selected' ?>
                                            value="<?php echo $value->id; ?>"><?php echo $value->name; ?></option>
                                        <?php }?>
                                </select>
                            <span id="subTypeSpan">
                            </span>
                            </b>
                            <?php if (isset($typeName)) echo "<em flag='m' style='color:red;' id='modifyType'>修改分类?</em>";  ?>
                        </TD>
                    </TR>
                    <TR>
                        <TD style="width: 10%">文章标题</TD>
                        <TD style="width: 90%"><input style="width: 300px"
                                                      value="<?php if (isset($domain)) echo $domain->name ?>"
                                                      name="name" type="text"/></TD>
                    </TR>
                    <TR>
                        <TD style="width: 10%">文章作者</TD>
                        <TD style="width: 90%"><input style="width: 100px"
                                                      value="<?php if (isset($domain)) echo $domain->author ?>"
                                                      name="author" type="text"/></TD>
                    </TR>
                    <TR>
                        <TD style="width: 10%">文章来源</TD>
                        <TD style="width: 90%"><input style="width: 500px"
                                                      value="<?php if (isset($domain)) echo $domain->source ?>"
                                                      name="source" type="text"/></TD>
                    </TR>
                    <TR>
                        <TD style="width: 10%">文章摘要</TD>
                        <TD style="width: 90%"><textarea name="subcontent"
                                                         style="width:800px;height:100px;"><?php if (isset($domain)) echo $domain->subcontent ?></textarea>
                        </TD>
                    </TR>
                    <TR>
                        <td><p></p></td>
                    </TR>
                    <TR>
                        <TD style="width: 10%">文章内容</TD>
                        <TD style="width: 90%"><textarea name="content"
                                                         style="width:800px;height:400px;visibility:hidden;"><?php if (isset($domain)) echo $domain->content ?></textarea>
                        </TD>
                    </TR>
                    <TR>
                        <TD style="width: 10%">点击数</TD>
                        <TD style="width: 90%"><input style="width: 50px"
                                                      value="<?php if (isset($domain)) echo $domain->hits ?>"
                                                      name="hits" type="text"/></TD>
                    </TR>
                    <TR>
                        <TD style="width: 10%">操作</TD>
                        <TD style="width: 90%"><input type="submit" value="保存"/></TD>
                    </TR>


                    </TBODY>
                </TABLE>
            </form>
        </TD>
        <TD width=15></TD>
    </TR>
    </TBODY>
</TABLE>
<script type="text/javascript">
    $(function () {
        $("#modifyType").bind("click", function () {
            var flag = $("#modifyType").text();
            if (flag == "取消?") {
                $("#articleTypeName").css("display", "");
                $("#articleTypeArea").css("display", "none");
                $("#modifyType").text("修改分类?");
            }
            if (flag == "修改分类?") {
                $("#articleTypeName").css("display", "none");
                $("#articleTypeArea").css("display", "");
                $("#modifyType").text("取消?");
            }

        })

        $("#parentType").bind("change", function () {
            $.ajax({
                url:"/index.php/ajax/loadSubType/" + $(this).val(),
                dataType:"html",
                async:false,
                type:"GET",
                beforeSend:function (jqXHR, settings) {
                    //这里显示进度条
                },
                error:function (jqXHR, textStatus, errorThrown) {

                },
                success:function (data, textStatus, jqXHR) {
                    data = eval("(" + data + ")");
                    if (data.length > 0) {
                        //如果有子分类
                        var hcodess = "";
                        $.each(data, function (n, j) {
                            hcodess = hcodess + '<option value="' + data[n].id + '">' + data[n].name + '</option>';
                        })
                        $("#subTypeSpan").html("<select id='subType' name='type_id'>" + hcodess + "</select>");
                    } else {
                        $("#subTypeSpan").html("");
                    }
                    if ($("#subType option").length == 0) {
                        $("#subTypeSpan").html("");
                        $("#parentType").attr("name", "type_id");
                    }
                    else {
                        $("#parentType").attr("name", "");
                        $("#subType").attr("name", "type_id");
                    }
                }
            })
        })
    })
</script>